package com.ruoyi.sms.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sms.domain.SmsConfig;
import com.ruoyi.sms.service.ISmsConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 短信配置
Controller
 *
 * @author ruoyi
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/system/smsConfig")
public class SmsConfigController extends BaseController {
    @Autowired
    private ISmsConfigService smsConfigService;

/**
 * 查询短信配置
列表
 */
@PreAuthorize("@ss.hasPermi('system:config:list')")
@GetMapping("/list")
    public TableDataInfo list(SmsConfig smsConfig) {
        startPage();
        List<SmsConfig> list = smsConfigService.selectSmsConfigList(smsConfig);
        return getDataTable(list);
    }

    /**
     * 导出短信配置
列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "短信配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsConfig smsConfig) {
        List<SmsConfig> list = smsConfigService.selectSmsConfigList(smsConfig);
        ExcelUtil<SmsConfig> util = new ExcelUtil<SmsConfig>(SmsConfig. class);
        util.exportExcel(response, list, "短信配置数据");
    }

    /**
     * 获取短信配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(smsConfigService.selectSmsConfigById(id));
    }

    /**
     * 新增短信配置

     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "短信配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsConfig smsConfig) {
        return toAjax(smsConfigService.insertSmsConfig(smsConfig));
    }

    /**
     * 修改短信配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "短信配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsConfig smsConfig) {
        return toAjax(smsConfigService.updateSmsConfig(smsConfig));
    }

    /**
     * 删除短信配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "短信配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(smsConfigService.deleteSmsConfigByIds(ids));
    }
}
